<?php
	
	//add by lin
	
	define('__ROOT__', dirname(dirname(__FILE__)));
	require_once(__ROOT__.'\models\Conn.php'); 
	require_once(__ROOT__.'\models\Citydevelop.php');
	//end add
	
class CitydevelopController extends Controller{

	private $id;

	public function base(){
		
	}

	public function show1(){
		$this->showCitydevelopList(1);
	}
	public function show2(){
		$this->showCitydevelopList(2);
	}	
	public function show3(){
		$this->showCitydevelopList(3);
	}	
	
	
	public function showCitydevelopList($i){
	
		//var_dump("citydevelopcontroller.php");

		$c1 = new Citydevelop();		
		if($i == 1)
			$citydevelop_list = $c1->listAll1();
		else if($i == 2)
			$citydevelop_list = $c1->listAll2();
		else if($i == 3)
			$citydevelop_list = $c1->listAll3();
		
		$arg_item = array();
		foreach( $citydevelop_list as $item )
		{
			array_push($arg_item,implode("/",$item));
		}
		$arg = implode(":",$arg_item);
		header("Location:app/views/citydevelop.php?list=$arg");
	}
	
	public function editPage()
	{
		$id = $this->id;
		$c1 = new Citydevelop();
		$item = $c1->getById($id);
		var_dump($item);
		$arg = implode(":",$item);
		header("Location:app/views/edit_citydevelop.php?item=$arg");
	}

	public function editItem()
	{
		$id = $this->id; 		
		$name = $_POST['name'];
		
		$time = $_POST['time'];
		$star = $_POST['star'];
		$label = $_POST['label'];
		$library = $_POST['library'];
		//$dir = $item['dir'];
		$file = $_FILES['upload'];
		$item = array("id"=>$id,"name"=>$name,"time"=>$time,"star"=>$star,"label"=>$label,"library"=>$library,"file"=>$file);
		$c1 = new Citydevelop();
		$c1->update($item);
		if($library == '城市发展案例库')
			$this->showCitydevelopList(1);
		else if($library == '城市百科知识库')
			$this->showCitydevelopList(2);
		else if($library == '城市数据知识库')
			$this->showCitydevelopList(3);		
	}
	
	public function deleteItem()
	{
		//var_dump('delete');
		$id = $this->id;
		//根据这个id值从数据库里删除一条记录
		
		$c1 = new Citydevelop();
		$item = $c1->getById($id);
		$library = $item['library'];
		
		$c1->delete($id);
		
		
		if($library == '城市发展案例库')
			$this->showCitydevelopList(1);
		else if($library == '城市百科知识库')
			$this->showCitydevelopList(2);
		else if($library == '城市数据知识库')
			$this->showCitydevelopList(3);		
	}
	
	public function addItemPage()
	{
		header("Location:app/views/add_citydevelop.php");
	}
	
	
	public function addItem()
	{

		$name = $_POST['name'];
		$time = $_POST['time'];
		$star = $_POST['star'];
		$label = $_POST['label'];
		$library = $_POST['library'];
		//$dir = $item['dir'];
		$file = $_FILES['upload'];
		//根据以上的值在数据库插入一条新记录
		$item = array("name"=>$name,"time"=>$time,"star"=>$star,"label"=>$label,"library"=>$library,"file"=>$file);
		$c1 = new Citydevelop();
		$c1->insert($item);
		if($library == '城市发展案例库')
			$this->showCitydevelopList(1);
		else if($library == '城市百科知识库')
			$this->showCitydevelopList(2);
		else if($library == '城市数据知识库')
			$this->showCitydevelopList(3);		
	}


	public function setParams($params)
	{
		$this->id = $params[0];
	}
}
